subroutine set_new_pos(lid,dist,px0,py0,pz0,dx,dy,dz,px,py,pz)
  use param
  use global_param,only:isqrt3
  use label_data_param,only:obj_type
  implicit none

  integer,intent(in) :: lid
  real(dbl),intent(in) :: dist,px0,py0,pz0,dx,dy,dz
  real(dbl),intent(out) :: px,py,pz

  integer :: dir
  real(dbl) :: dr,d1,rn1,rn2

  dr=dist*isqrt3

  if (obj_type(lid)%does_move) then

     select case(obj_type(lid)%motion_type)
     case(0)
        px=px0
        py=py0
        pz=pz0
     case(1)
        ! 1-d motion
        call random_number(rn1)
        if (rn1.le.0.5) then
           px=px0+dx*dr
           py=py0+dy*dr
           pz=pz0+dr*dr
        else
           px=px0-dx*dr
           py=py0-dy*dr
           pz=pz0-dr*dr
        end if
     case(2)
     case(3)
        ! 3-d random lattice motion
        call random_number(rn1)
        dir=ceiling(rn1*8.0)
        select case(dir)
        case(1)
           px=px0+dr
           py=py0+dr
           px=pz0+dr
        case(2)
           px=px0-dr
           py=py0+dr
           pz=pz0+dr
        case(3)
           px=px0-dr
           py=py0-dr
           pz=pz0+dr
        case(4)
           px=px0+dr
           py=py0-dr
           pz=pz0+dr
        case(5)
           px=px0+dr
           py=py0+dr
           pz=pz0-dr
        case(6)
           px=px0-dr
           py=py0+dr
           pz=pz0-dr
        case(7)
           px=px0-dr
           py=py0-dr
           pz=pz0-dr
        case(8)
           px=px0+dr
           py=py0-dr
           pz=pz0-dr
        end select
     case(4)
        ! 3-D random latticeless motion
        call random_number(rn1)
        rn1=rn1*2.0*pi
        call random_number(rn2)
        rn2=rn2*2.0*pi
        d1=cos(rn2)
        px=px0+dr*cos(rn1)*d1
        py=py0+dr*sin(rn1)*d1
        pz=pz0+dr*sin(rn2)
     end select
  else
     px=px0
     py=py0
     pz=pz0
  end if

  return

end subroutine set_new_pos
